#include <my_head.h>

int main(int argc, const char *argv[]){
    // 创建套接字
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if(-1 == sockfd)
        ERR_LOG("socket error");
    
    // 填充 服务器! 网络信息结构体
    struct sockaddr_in serveraddr;
    serveraddr.sin_family = AF_INET;
    serveraddr.sin_port = htons(8888);
    serveraddr.sin_addr.s_addr = inet_addr("202.202.202.10");
    socklen_t serveraddr_len = sizeof(serveraddr);

    // 与服务器建立连接
    if(-1 == connect(sockfd, (struct sockaddr *)&serveraddr, serveraddr_len))
        ERR_LOG("connect error");
    printf("与服务器连接成功...\n");

    // 收发数据
    char buff[128] = {0};
    fgets(buff, sizeof(buff), stdin);
    buff[strlen(buff)-1] = '\0';
    // 给服务器发表达式
    write(sockfd, buff, sizeof(buff));
    // 接收服务器发来的计算结果
    memset(buff, 0, sizeof(buff));
    read(sockfd, buff, sizeof(buff));
    // 输出
    printf("计算的结果为:[%s]\n", buff);

    // 关闭套接字
    close(sockfd);

    return 0;
}